package com.ninogame.state;

import java.io.IOException;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParserException;

import com.ninogame.BitmapFont;
import com.ninogame.GameLayer;
import com.ninogame.GameLib;
import com.ninogame.IConstant;
import com.ninogame.MazeEscape;
import com.ninogame.Map;
import com.ninogame.Actor.Creature;
import com.ninogame.Actor.Explorer;
import com.ninogame.resolution.DEF;


import android.R.color;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.view.KeyEvent;


public class StateHowToPlay extends MazeEscape implements IConstant
{
	public static RectF rectF = null;
	public static int page = 0;

	public static synchronized void SendMessage(int type)
	{

		switch (type)
		{
		case MESSAGE_CTOR:
			rectF = new RectF(DEF.HOWTOPLAY_BACKGROUND_X, DEF.HOWTOPLAY_BACKGROUND_Y, DEF.HOWTOPLAY_BACKGROUND_X + DEF.HOWTOPLAY_BACKGROUND_W, DEF.HOWTOPLAY_BACKGROUND_Y + DEF.HOWTOPLAY_BACKGROUND_H);

			break;
		case MESSAGE_UPDATE:
			
			if (MazeEscape.isTouchReleaseInRect(DEF.HOWTOPLAY_BACKGROUND_X + DEF.HOWTOPLAY_BACKGROUND_W - DEF.HOWTOPLAY_BUTTON_W - 8, DEF.HOWTOPLAY_BACKGROUND_Y + 8, DEF.HOWTOPLAY_BUTTON_W, DEF.HOWTOPLAY_BUTTON_H)) {
				if (StateGameplay.isIngame)
					changeState(STATE_IGM, true, true);
				else
					changeState(STATE_MAINMENU, true, true);
			}
			break;
		case MESSAGE_PAINT:
			if (!StateGameplay.isIngame) {
				MazeEscape.mainPaint.setColor(Color.BLACK);
				MazeEscape.mainPaint.setStyle(Style.FILL);
				mainCanvas.drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, MazeEscape.mainPaint);
				matrix.reset();
				matrix.setScale(SCREEN_WIDTH * 1f / 800, SCREEN_HEIGHT * 1f / 1280);
				mainCanvas.drawBitmap(StateMainMenu.splashBitmap, matrix, mainPaint);
			} else {
				StateGameplay.SendMessage(MESSAGE_PAINT);
			}
			MazeEscape.mainPaint.setStyle(Style.FILL);
			MazeEscape.mainPaint.setARGB(200, 0, 0, 0);
			MazeEscape.mainCanvas.drawRect(0, 0, MazeEscape.SCREEN_WIDTH, MazeEscape.SCREEN_HEIGHT, MazeEscape.mainPaint);
			MazeEscape.mainPaint.setStyle(Style.FILL_AND_STROKE);
			MazeEscape.mainPaint.setColor(Color.rgb(67, 120, 167));
			MazeEscape.mainCanvas.drawRoundRect(rectF, 25, 25, MazeEscape.mainPaint);//DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H

			//draw text

			MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "HOW TO PLAY", DEF.HOWTOPLAY_TITLE_X, DEF.HOWTOPLAY_TITLE_Y, BitmapFont.ALIGN_CENTER);

			if (page == 0) { 
				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_GUIDE_ME, 30, DEF.HOWTOPLAY_TITLE_CONTENT_Y + DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H);
				MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "Who are you ? : ", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H, 0);

				MazeEscape.fontbig_White.drawString(MazeEscape.mainCanvas, "You are kaban in the board", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H + 15, DEF.HOWTOPLAY_BACKGROUND_W - 300, 0);
				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_GUIDE_MOVE, 30, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 3*DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H);

				MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "How to move?:", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 3 * DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H, 0);

				MazeEscape.fontbig_White.drawString(MazeEscape.mainCanvas, "Using dpad to move on the board, if you want to skip you move touch in center button of dpad", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 3 * DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H + 15, DEF.HOWTOPLAY_BACKGROUND_W - 300, 0);

				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_GUIDE_BOARD, 30, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 5*DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H +(BitmapFont.numWrapLines -1)*15);

				MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "How To do?:", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 5 * DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H + (BitmapFont.numWrapLines -1)*15, 0);

				MazeEscape.fontbig_White.drawString(MazeEscape.mainCanvas, "Exit the board by move to door and don't catch by enemy", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 5 * DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H + 15+(BitmapFont.numWrapLines -1)*15, DEF.HOWTOPLAY_BACKGROUND_W - 300, 0);
			}else if(page ==1){
				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_GUIDE_ME, 30, DEF.HOWTOPLAY_TITLE_CONTENT_Y + DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H);
				MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "Who are you : ", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H, 0);

				MazeEscape.fontbig_White.drawString(MazeEscape.mainCanvas, "You are kaban in the board", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H + 15, DEF.HOWTOPLAY_BACKGROUND_W - 300, 0);
				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_GUIDE_ENEMY_ALL, 30, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 3*DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H);

				MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "Who are Enemy:", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 3 * DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H, 0);

				MazeEscape.fontbig_White.drawString(MazeEscape.mainCanvas, "opponents is the animals will pursue you on the board", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 3 * DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H + 15, DEF.HOWTOPLAY_BACKGROUND_W - 300, 0);

				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_GUIDE_TAP, 30, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 5*DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H +(BitmapFont.numWrapLines -1)*15);

				MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "Trap:", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 5 * DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H + (BitmapFont.numWrapLines -1)*15, 0);

				MazeEscape.fontbig_White.drawString(MazeEscape.mainCanvas, "Use DPAD arrow to move on board. center(skip )", DEF.HOWTOPLAY_TITLE_CONTENT_X, DEF.HOWTOPLAY_TITLE_CONTENT_Y + 5 * DEF.HOWTOPLAY_TITLE_CONTENT_SPACE_H + 15+(BitmapFont.numWrapLines -1)*15, DEF.HOWTOPLAY_BACKGROUND_W - 300, 0);
			}
			if (MazeEscape.isTouchDrapInRect(DEF.HOWTOPLAY_BACKGROUND_X + DEF.HOWTOPLAY_BACKGROUND_W - DEF.HOWTOPLAY_BUTTON_W - 8, DEF.HOWTOPLAY_BACKGROUND_Y + 8, DEF.HOWTOPLAY_BUTTON_W, DEF.HOWTOPLAY_BUTTON_H))
				StateGameplay.spriteDPad.drawAFrame(MazeEscape.mainCanvas, DEF.FRAME_CANCEL_HIGHTLIGHT, DEF.HOWTOPLAY_BACKGROUND_X + DEF.HOWTOPLAY_BACKGROUND_W - DEF.HOWTOPLAY_BUTTON_W / 2 - 8, DEF.HOWTOPLAY_BACKGROUND_Y + DEF.HOWTOPLAY_BUTTON_H / 2 + 8);
			else
				StateGameplay.spriteDPad.drawAFrame(MazeEscape.mainCanvas, DEF.FRAME_CANCEL_NORMAL, DEF.HOWTOPLAY_BACKGROUND_X + DEF.HOWTOPLAY_BACKGROUND_W - DEF.HOWTOPLAY_BUTTON_W / 2 - 8, DEF.HOWTOPLAY_BACKGROUND_Y + DEF.HOWTOPLAY_BUTTON_H / 2 + 8);

			break;
		case MESSAGE_DTOR:
			break;
		}
	}
}
